package me.algo.lst;

import java.util.HashSet;
import java.util.List;

/**
 * @author guozheng
 * @date 2024/4/13
 */
public class L1 {


    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummy = new ListNode();
        ListNode rcu = dummy;
        HashSet<Integer> set = new HashSet<>();
        ListNode cur = head;
        while (cur != null) {
            int val = cur.val;
            boolean contains = set.contains(val);
            if (!contains) {
                rcu.next = cur;
                rcu = rcu.next;
                set.add(val);
            }
            cur = cur.next;
        }
        rcu.next = null;
        return dummy.next;
    }

}
